<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2019/1/7
 * Time: 14:14
 */

namespace app\sports_admin\model;


use think\Model;
use think\Request;
use traits\model\SoftDelete;

class FeedBack extends Model
{
    use SoftDelete;
    protected $table = "feedback";
    protected $pk    = "id";
    protected $autoWriteTimestamp = true;
    protected $hidden = ['update_time','delete_time'];
    public static function getTypeAttr($values)
    {
        //1 咨询  2 建议  3功能故障
        switch ($values){
            case 1 : return '咨询';
            case 2 : return '<span style="color: #0000FF">建议</span>';
            case 3 : return '<span style="color:red;">功能故障</span>';
        }
    }
    //管理员
    public function school()
    {
        return $this->belongsTo("school","school_id","school_id")->field('school_id,school_name');
    }
    //教师
    public function teacher()
    {
       return $this->belongsTo("teacher","school_id",'id')->field('id,teacher_name');
    }
    /**
     * @param $page 页数
     * @param $rows 行数
     * @param $sort 排序的字段
     * @param $sortOrder 升降序
     * @param $searchName 关键字
     */
    public static function feedBackList($page,$rows,$sort,$sortOrder,$searchName)
    {
        $result = self::with("school,teacher")
            ->order("{$sort}","{$sortOrder}")
            ->page($page)
            ->limit($rows)
            ->field('id,school_id,title,type,status,state')->select();
        $total = self::with("school,teacher")
            ->count();
        return json(['rows'=>$result,'total'=>$total]);
    }

    /**
     *反馈信息详情
     * @param $id 反馈信息id
     */
    public static function detail($id)
    {
        return self::with("school,teacher")->where("id",$id)->find();
    }
}